package com.tom.demo;

import com.github.lianjiatech.retrofit.spring.boot.annotation.RetrofitScan;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
@RetrofitScan(basePackages = {"com.tom.demo.thirdparty"})
@Slf4j
@MapperScan(basePackages = {"com.tom.demo.mapper"})
@SpringBootApplication
@EnableTransactionManagement
@EnableScheduling
@EnableAsync // 启用异步方法执行
public class TemplateApiApplication {
    public static void main(String[] args) {
        SpringApplication.run(TemplateApiApplication.class, args);
    }

    @Bean
    public ApplicationRunner applicationRunner(Environment environment) {
        return args -> {
            String localHostIP = InetAddress.getLocalHost().getHostAddress();
            String serverPort = environment.getProperty("server.port");
            String contextPath = environment.getProperty("server.servlet.context-path");

            String logMessage =
                    "  __  __           _       _     _               \n" +
                            " |  \\/  |         (_)     | |   | |              \n" +
                            " | \\  / |_   _ ___ _  __ _| |__ | |_ ___ _ __    \n" +
                            " | |\\/| | | | / __| |/ _` | '_ \\| __/ _ \\ '__|   \n" +
                            " | |  | | |_| \\__ \\ | (_| | |_) | ||  __/ |      \n" +
                            " |_|  |_|\\__,_|___/_|\\__,_|_.__/ \\__\\___|_|      \n" +
                            "\n" +
                            "============ 系统 启动成功 ============\n" +
                            "  欢迎使用系统！\n" +
                            "  系统已成功启动，所有服务准备就绪。\n" +
                            "  端口号: " + serverPort + "\n" +
                            "  上下文路径: " + contextPath + "\n" +
                            "  应用访问地址: http://"+ localHostIP +":"+ serverPort + contextPath + "\n" +
                            "  接口文档地址: http://"+ localHostIP +":"+ serverPort + contextPath + "/doc.html\n" +
                            "  开始您的高效工作之旅吧！\n";
            log.info("<================{}=======================>", logMessage);
        };
    }
}
